package util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.HashMap;

public class property 
{
	private HashMap<String, String> map;
	public property(File file) throws IOException, ClassNotFoundException
	{
		BufferedReader br =new BufferedReader(new FileReader(file));
		String line;
		String[] attrs;
		map= new HashMap<String, String>();
		while((line=br.readLine())!=null)
		{
			attrs=line.split("=");
			map.put(attrs[0].trim(), attrs[1].trim());
		}
	}
	public property(String file_address) throws IOException, ClassNotFoundException
	{
		this(new File(file_address));
	}
    public String getString(String  key, String defaultvalue)
    {
    	if(!map.containsKey(key))
    		return defaultvalue;
    	else {
    		return map.get(key);
		}
    	
    }
    public int getInt(String  key, int defaultvalue)
    {
    	if(!map.containsKey(key))
    		return defaultvalue;
    	else {
    		return Integer.parseInt(map.get(key));
		}
    	
    } 
    public double getDouble(String  key, double defaultvalue)
    {
    	if(!map.containsKey(key))
    		return defaultvalue;
    	else {
    		return Double.parseDouble(map.get(key));
		}
    	
    }
    public void setString(String key, String  value)
    {
    	map.put(key, value);
    }
    public void setInt(String key, int  value)
    {
    	map.put(key, String.valueOf(value));
    }
    public void setDouble(String key, double  value)
    {
    	map.put(key, String.valueOf(value));
    }
   
}
